import formRequest from "@/utils/formRequest";
import jsonRequest from "@/utils/jsonRequest";

export function getBookList(searchData) {
  if (searchData == null) {
    searchData.bookName = "";
    searchData.bookType = "";
  }
  return formRequest({
    url: "/getBookList",
    method: "post",
    data: {
      bookName: searchData.bookName,
      bookType: searchData.bookType,
    },
  });
}

export function getPagedBookInfo(searchData) {
  if (searchData == null) {
    searchData.bookName = "";
    searchData.bookType = "";
    searchData.pageSize = 20;
    searchData.pageNum = 1;
  }
  return formRequest({
    url: "/getPagedBookList",
    method: "post",
    data: {
      bookName: searchData.bookName,
      bookType: searchData.bookType,
      pageSize: searchData.pageSize,
      pageNum: searchData.pageNum,
    },
  });
}

export function delBookInfo(id) {
  return formRequest({
    url: "/delBookInfo",
    method: "post",
    data: {
      id: id,
    },
  });
}

export function modifyBookInfo(book) {
  return jsonRequest({
    url: "/modifyBookInfo",
    method: "post",
    data: {
      id: book.id,
      bookName: book.bookName,
      bookType: book.bookType,
      author: book.author,
      publishDate: book.publishDate,
      publisher: book.publisher,
    },
  });
}

export function addBookInfo(book) {
  return jsonRequest({
    url: "/addBookInfo",
      method: "post",
      data: {
          bookName: book.bookName,
          bookType: book.bookType,
          author: book.author,
          publishDate: book.publishDate,
          publisher: book.publisher,
      },
  });
}

// get client ip address
export function getIpAddress() {
    return formRequest({
        url: "/getIpAddress",
        method: "get",
        data: {},
    });
}
